﻿#pragma execution_character_set("utf-8")
#include "trayiconmenu.h"

TrayIconMenu::TrayIconMenu(QWidget *parent)
    :QMenu{parent},
    menuLayout(new QVBoxLayout()),
    quitButton(new QPushButton(tr("退出")))
{
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setFixedWidth(180);
    this->setStyleSheet(QString("\
        QMenu {\
            border:1px solid rgb(153, 153, 153);\
            border-radius: 4px; \
            background-color: white;\
    }"));
    setLayout(menuLayout);
    menuLayout->setContentsMargins(6,6,6,6);
    menuLayout->setSpacing(2);
    quitButton->setFixedHeight(28);
    connect(quitButton,&QPushButton::clicked,this,&TrayIconMenu::quit);
    menuLayout->addWidget(quitButton);
}
void TrayIconMenu::insertLogoutButton(){
    logoutButton=new QPushButton(tr("注销"));
    logoutButton->setFixedHeight(28);
    connect(logoutButton,&QPushButton::clicked,this,&TrayIconMenu::logout);
    menuLayout->insertWidget(menuLayout->count()-1,logoutButton);
}
void TrayIconMenu::removeLogoutButton(){
    if(logoutButton!=nullptr){
        delete logoutButton;
        logoutButton=nullptr;
        clear();
    }
}
